package com.xinxing.learning.log.desensitization.controller;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.xinxing.learning.log.desensitization.entity.Student;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;

@Slf4j
@RestController
@RequestMapping("/log")
public class LogController {
    @GetMapping("/info")
    public String info() throws JsonProcessingException {
        log.info("localMobile:{},localMobile:{}", "023-55327459", "123456");
        // 规范语法 - 推荐,格外推荐使用=分割。
        log.info("your email:{},your phone:{}", "123456789@qq.com", "15310763497");
        log.info("your email={},your cellphone={}", "123456789@qq.com", "15310763497");
        log.info("email:{},mobile:{}", "123456789@qq.com", "023-55327459");
        log.info("identity:{}", "123456789012345");
        // Map类型
        HashMap<String, String> map = new HashMap<>();
        map.put("phone", "15310763497");
        map.put("email", "123456789@qq.com");
        log.info("one map={}", map);
        log.info("one json={}", "{" +
                "\t\"email\":\"123456789@qq.com\"," +
                "\t\"phone\":\"15310764682\"" + "}");
        // 对象类型
        log.info("student:{}", new Student(1L, "柳成荫", "15372746384", "530365199703153648"));
        ObjectMapper objectMapper = new ObjectMapper();
        log.info("student:{}",objectMapper.writeValueAsString(new Student(1L, "柳成荫", "15372746384", "530365199703153648")));
        // 对于需要完全密文的
        log.info("password:{}", "189498asd6489s");
        // 非规范 - 但也能用 - 不推荐
        log.info(" mobile:{},email:{}", 123456, "123456789@qq.com");
        log.info("mobile :{},email:{}", 123456, "123456789@qq.com");
        log.info("mobile :{} : email:{}", 123456, "123456789@qq.com");
        return "success";
    }
}
